package org.framework.common.api.support.model;

import java.io.Serializable;

import org.framework.common.api.entity.CommonEntityAware;
import org.framework.common.api.service.bo.CommonBoAware;
import org.framework.common.ext.util.PropertiesUtil;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 业务操作模型
 * <p>描述: 用于注册业务操作辅助对象，如bo、jdbc等</p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date 2016年9月6日 下午12:18:15
 * @version 1.0.2016
 */
public class ProcessModel implements Serializable{
	
	/** serialVersionUID(long):. */
	private static final long serialVersionUID = 8771873993513456404L;

	// 公共业务对象
	public CommonBoAware<CommonEntityAware<String>, String> bo;
	
	// 线程池
	public ThreadPoolTaskExecutor executor;
	
	// JDBC
	public JdbcTemplate jdbc;
	
	// JDBC CALL
	public SimpleJdbcCall call;
	
	// JDBC SQL PROPERTIES
	public PropertiesUtil properties;
	
	// JDBC BY NAMED PARAMETER
	public NamedParameterJdbcTemplate ndbc;
	
	private static ProcessModel intance;
	
	public static ProcessModel factory(){
		if(intance == null){
			intance = new ProcessModel();
		}
		return intance;
	}
	
	private ProcessModel() {
		
	}
	
	/**
	 * 注册业务操作处理器.
	 * @param bo
	 * @param jdbc
	 * @param executor
	 * @author chanlong(陈龙)
	 * @date 2016年9月6日 下午12:19:52
	 */
	public void registerProcess(final CommonBoAware<CommonEntityAware<String>, String> bo, final JdbcTemplate jdbc, final ThreadPoolTaskExecutor executor){
		if(this.bo == null) this.bo = bo;
		if(this.jdbc == null) this.jdbc = jdbc;
		if(this.executor == null) this.executor = executor;
		if(this.call == null) this.call = jdbc != null ? new SimpleJdbcCall(jdbc) : null;
		if(this.ndbc == null) this.ndbc = jdbc != null ? new NamedParameterJdbcTemplate(jdbc.getDataSource()) :  null;
		
		registerProperties();
	}
	
	public void registerProperties(){
		properties = PropertiesUtil.loader("/config/properties/jdbc.xml");
	}

	public CommonBoAware<CommonEntityAware<String>, String> getBo() {
		return bo;
	}

	public void setBo(CommonBoAware<CommonEntityAware<String>, String> bo) {
		this.bo = bo;
	}

	public ThreadPoolTaskExecutor getExecutor() {
		return executor;
	}

	public void setExecutor(ThreadPoolTaskExecutor executor) {
		this.executor = executor;
	}

	public JdbcTemplate getJdbc() {
		return jdbc;
	}

	public void setJdbc(JdbcTemplate jdbc) {
		this.jdbc = jdbc;
	}

	public SimpleJdbcCall getCall() {
		return call;
	}

	public void setCall(SimpleJdbcCall call) {
		this.call = call;
	}

	public NamedParameterJdbcTemplate getNdbc() {
		return ndbc;
	}

	public void setNdbc(NamedParameterJdbcTemplate ndbc) {
		this.ndbc = ndbc;
	}
}
